home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_015 / dazzle / dazzle.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  22KB  |  928 lines

  1. /***************************************************************************
  2.  * dazzle.c
  3.  *
  4.  *            A simple graphics program demo for the Amiga by
  5.  *            M. Peter Engelbrite
  6.  *
  7.  *          A note about the name "dazzle"- back in the days of
  8.  *          MITS(Altair), SWTP and Processor Technology, there was
  9.  *          a color graphics board for the S-100 named the "Dazzler".
  10.  *          A computer program came with this board named "Dazzle".
  11.  *          That program had the same type of eight-fold symmetry that
  12.  *          my program does (although it was much simpler in the
  13.  *          generation of the patterns).  Legend has it that a 'mystery'
  14.  *          programmer wrote that program in a few hours, and sold it
  15.  *          to Chromemco (the manufacturer) for a song.  Whenever I
  16.  *          experiment with a graphics system,  I test it with some
  17.  *          version of this program and name it Dazzle in honor of that
  18.  *          mystery programmer.
  19.  *
  20.  *            Many thanks to Scott Ballantyne for "sparks", portions of
  21.  *          which were used in this program.
  22.  *
  23.  ************************************************************************/
  24.  
  25. /* Because of a wierd bug in the current Manx C compiler I am using */
  26. /* (versions 1.99G), the comments below have been moved to their current */
  27. /* location, from the end of the include file lines.  Fred Fish, 3/8/86 *
  28.  
  29. /* Not all of these are used -- I include them */
  30. /* 'cause I'm sick of compiler warnings.       */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/nodes.h>
  34. #include <exec/lists.h>
  35. #include <exec/exec.h>
  36. #include <exec/execbase.h>
  37. #include <exec/ports.h>
  38. #include <exec/devices.h>
  39. #include <exec/memory.h>
  40. #include <hardware/blit.h>
  41. #include <graphics/copper.h>
  42. #include <graphics/regions.h>
  43. #include <graphics/rastport.h>
  44. #include <graphics/gfxbase.h>
  45. #include <graphics/gfxmacros.h>
  46. #include <graphics/gels.h>
  47. #include <intuition/intuition.h>
  48. #ifdef LATTICE
  49. #include <lattice/math.h>
  50. #else
  51. #include <math.h>
  52. #endif
  53.  
  54. struct IntuitionBase *IntuitionBase = NULL;
  55. struct GfxBase *GfxBase = NULL;
  56.  
  57. #define MAXX   320
  58. #define MAXY   200
  59. #define row 100
  60. #define col 150
  61. #define INIT 1
  62. #define EXEC 0
  63.  
  64. /* if you make any changes, please update the version number 
  65.    following the decimal */
  66.  
  67. struct NewScreen MyScreen =
  68. { 0,0,MAXX,MAXY,5,0,1,0, CUSTOMSCREEN, NULL,
  69.   "Dazzle 1.0 by M. Peter Engelbrite",
  70.   0,0,};
  71.  
  72.    struct NewWindow DrawWindow = {
  73.       0,0,MAXX,MAXY,
  74.       0,1,
  75.       MENUPICK,
  76.       BORDERLESS | BACKDROP | ACTIVATE,
  77.       NULL,
  78.       NULL,
  79.       NULL,
  80.       NULL,
  81.       NULL,
  82.       0,0,0,0,
  83.       CUSTOMSCREEN,
  84.    };
  85.  
  86. struct Screen *Screen = NULL;
  87. struct Window *Backdrop = NULL;
  88. struct RastPort *DrawRP;
  89. struct ViewPort *DrawVP;
  90. struct IntuiMessage  *message;
  91.  
  92. struct MenuItem OnlyMenuItems[3];
  93. struct IntuiText OnlyMenuText[3];
  94. struct Menu OnlyMenu[1];
  95. static int PauseMode, TitleOn;
  96. static int offsa, offsb;
  97. static char color, cyclecnt;
  98. static int redvalue[32], greenvalue[32], bluevalue[32];
  99.  
  100. /* these are utility functions for use in changing colors */
  101. /* randomly select a new color, also randomizes the hue for that color */
  102. newcolor()
  103. {
  104.   color = RangeRand(31) + 1; /* leave lower colors alone */
  105.   /* give it a new look, also */
  106.   SetRGB4(DrawVP,
  107.           color,
  108.           (redvalue[color] = RangeRand(16)),
  109.           (greenvalue[color] =  RangeRand(16)),
  110.           (bluevalue[color] =  RangeRand(16))
  111.          );
  112.   SetAPen(DrawRP,color);
  113. }
  114.  
  115. /* selects the next in sequence of available colors */
  116. nextcolor()
  117. {
  118.   if(++color > 31) color = 1;
  119.   SetAPen(DrawRP,color);
  120. }
  121.  
  122. /* sets a specific color */
  123. setcolor(coler)
  124. int coler;
  125. {
  126.   color = coler;
  127.   if(color == 0) color = 1;
  128.   SetAPen(DrawRP,color);
  129. }
  130.  
  131. /* user definable graphics functions */
  132. /* each function should set offsa and offsb and optionally chage the color
  133.    it may maintain local variables, it should accept a value init which
  134.    is set to TRUE to indicate that initialization is to occur.  offsa and
  135.    offsb should range between 0 and 99 (overflow is not fatal, though).
  136.    The function may call setcolor(n), newcolor(), or nextcolor() to change
  137.    the color.  The name of your function must be added to the structure
  138.    dotfunc in do_dazzle() at the end of this module.  You will find that
  139.    it is very easy to experiment and obtain interesting effects.
  140. */
  141.  
  142. streamer(init)
  143. int init;
  144. {
  145.   static int cnt1, cnt2, cnt3;
  146.  
  147.   if(init)
  148.     {
  149.       cnt1 = cnt2 = 0;
  150.       cnt3 = 24;
  151.     }
  152.   if(cnt1++ > cnt2)
  153.     {
  154.       offsa -= cnt2;
  155.       cnt1 = 0;
  156.       cnt2 = cnt2 + 1;
  157.       if (cnt2 > cnt3)
  158.         {
  159.           cnt2 = 0;
  160.           if((cnt3 = cnt3 + RangeRand(4)) > 44) cnt3 = 0; 
  161.         }
  162.       if(offsb++ >= 99) offsb = 0;
  163.     }
  164.   if(offsa++ >= 99) offsa = 0;
  165.   if(RangeRand(1000) == 0) newcolor();
  166. }
  167.  
  168. lotsadots(init)
  169. int init;
  170. {
  171.         offsa = RangeRand(100);
  172.         offsb = RangeRand(100);
  173.         newcolor();
  174. }
  175.  
  176. ribbons(init)
  177. int init;
  178. {
  179.   static int cnt1, cnt2, cnt3;
  180.  
  181.   if(init)
  182.     {
  183.       cnt1 = cnt2 = 0;
  184.       cnt3 = 24;
  185.     }
  186.   if(cnt1++ > cnt2)
  187.     {
  188.       offsa -= cnt2;
  189.       cnt1 = 0;
  190.       cnt2 = cnt2 + 1;
  191.       if (cnt2 > cnt3)
  192.         {
  193.           cnt2 = 0;
  194.           if((cnt3 = cnt3 + RangeRand(4)) > 44) cnt3 = 0; 
  195.         }
  196.       nextcolor();
  197.       if(offsb++ >= 99) offsb = 0;
  198.     }
  199.   if(offsa++ >= 99) offsa = 0;
  200.   if(RangeRand(1000) == 0) newcolor();
  201. }
  202.  
  203.  
  204. scribble(init)
  205. int init;
  206. {
  207.  
  208.   if((offsa = offsa + RangeRand(3) - 1) > 99) offsa = 0;
  209.   if((offsb = offsb + RangeRand(3) - 1) > 99) offsb = 0;
  210.   if(RangeRand(500) == 0) newcolor();
  211. }
  212.  
  213. curves(init)
  214. int init;
  215. {
  216.   static int wid, andx, bndx, aspeed, bspeed;
  217.  
  218.   if(init)
  219.     {
  220.       andx = bndx = wid = 0;
  221.       aspeed = RangeRand(64) + 20;
  222.       bspeed = RangeRand(64) + 20;
  223.       newcolor();
  224.     }
  225.  
  226.   if((wid = (wid + 1) & 15) == 0)
  227.     {
  228.       offsa = (int)(sin((double)andx * .0005) * 42.0) + 42;
  229.       offsb = (int)(sin((double)bndx * .0005) * 42.0) + 42;
  230.       andx += aspeed;
  231.       bndx += bspeed;
  232.       if(andx > 99999) andx = 0;
  233.       if(bndx > 99999) bndx = 0;
  234.       nextcolor();
  235.     }
  236.   else
  237.     offsa++;
  238. }
  239.  
  240. lines(init)
  241. int init;
  242. {
  243.   static int wid, aspeed, bspeed, ndx;
  244.  
  245.   if(init)
  246.     {
  247.       wid = ndx = 0;
  248.       aspeed = bspeed = 1;
  249.     }
  250.   if((wid = (wid + 1) & 3) == 0)
  251.     {
  252.       offsa += aspeed;
  253.       ndx += bspeed;
  254.       if(offsa < 0)
  255.         {
  256.           aspeed = 1;
  257.           offsa = 0;
  258.           if(RangeRand(3) == 0) newcolor();
  259.         }
  260.       if(ndx < 0)
  261.         {
  262.           bspeed = RangeRand(4) + 1;
  263.           ndx = 0;
  264.         }
  265.       if(offsa >= 100)
  266.         {
  267.           aspeed = - 1;
  268.           offsa = 99;
  269.         }
  270.       if(ndx >= 97)
  271.         {
  272.           bspeed = 0 - (RangeRand(4) + 1);
  273.           ndx = 96;
  274.          }
  275.       offsb = ndx;
  276.     }
  277.   else
  278.     offsb++;
  279. }
  280.  
  281. squares(init)
  282. int init;
  283. {
  284.         static int aend, astrt, sqcnt;
  285.  
  286.         if(init) sqcnt = 0;
  287.         if(sqcnt != 0) {
  288.                 if(++offsa > aend) {
  289.                         offsa = astrt;
  290.                         offsb++;
  291.                         sqcnt--;
  292.                         if(offsb > 99) {
  293.                                 sqcnt = 0;
  294.                                 offsb = 99;
  295.                         }
  296.                    nextcolor();
  297.                 }
  298.         }
  299.         if(sqcnt == 0) {
  300.                 sqcnt = (RangeRand(10)) + 8;
  301.                 offsa = (astrt = RangeRand(64));
  302.                 aend = (RangeRand(64)) + astrt + 8;
  303.                 if(aend > 99) aend = 99;
  304.                 while((offsb = RangeRand(128)) > 99);
  305.                 newcolor();
  306.         }
  307. }
  308.  
  309. triangles(init)
  310. int init;
  311. {
  312.         static int aend, astrt, sqcnt;
  313.  
  314.         if(init) sqcnt = 0;
  315.         if(sqcnt != 0) {
  316.                 if(++offsa > aend) {
  317.                         nextcolor();
  318.                         astrt++;
  319.                         aend--;
  320.                         if(astrt >= aend) {
  321.                                 sqcnt = 0;
  322.                         } else {
  323.                                 offsa = astrt;
  324.                                 offsb++;
  325.                                 if(offsb > 99) {
  326.                                         sqcnt = 0;
  327.                                         offsb = 99;
  328.                                 }
  329.                         }
  330.                 }
  331.         }
  332.         if(sqcnt == 0) {
  333.                 sqcnt = 1;
  334.                 offsa = (astrt = RangeRand(64));
  335.                 aend = RangeRand(64) + astrt + 8;
  336.                 if(aend > 99) aend = 99;
  337.                 offsb = RangeRand(100);
  338.                 newcolor();
  339.         }
  340. }
  341.  
  342. zigzags(init)
  343. int init;
  344. {
  345.   static int cnt, andx, bndx;
  346.  
  347.   if(init) cnt = -1;
  348.   if(cnt-- <= 0)
  349.     {
  350.       andx = RangeRand(3) - 1;
  351.       bndx = RangeRand(3) - 1;
  352.       cnt = RangeRand(15);
  353.       newcolor();
  354.     }
  355.   offsa += andx;
  356.   offsb += bndx;
  357.   if(offsa <= 0 || offsa >= 99) andx = -andx;
  358.   if(offsb <= 0 || offsb >= 99) bndx = -bndx;
  359.  
  360. }
  361.  
  362. grid(init)
  363. int init;
  364. {
  365.   static int aend, astrt, xcol, imagepnt, imagestrt;
  366.   static char image[] =
  367.     {
  368.  
  369.       0,0,0,1,1,0,0,0,
  370.       0,0,0,1,1,0,0,0,
  371.       0,0,0,0,1,1,0,0,
  372.       1,1,0,0,0,1,1,1,
  373.       1,1,1,0,0,0,1,1,
  374.       0,0,1,1,0,0,0,0,
  375.       0,0,0,1,1,0,0,0,
  376.       0,0,0,1,1,0,0,0,
  377.  
  378.       0,0,0,1,1,0,0,0,
  379.       0,0,0,1,1,0,0,0,
  380.       0,0,1,1,0,0,0,0,
  381.       1,1,1,0,0,0,1,1,
  382.       1,1,0,0,0,1,1,1,
  383.       0,0,0,0,1,1,0,0,
  384.       0,0,0,1,1,0,0,0,
  385.       0,0,0,1,1,0,0,0,
  386.  
  387.       0,0,0,1,1,0,0,0,
  388.       0,0,0,1,1,0,0,0,
  389.       0,0,0,1,1,0,0,0,
  390.       1,1,0,1,1,0,1,1,
  391.       1,1,0,1,1,0,1,1,
  392.       0,0,0,1,1,0,0,0,
  393.       0,0,0,1,1,0,0,0,
  394.       0,0,0,1,1,0,0,0,
  395.  
  396.       0,0,0,1,1,0,0,0,
  397.       0,0,0,1,1,0,0,0,
  398.       0,0,0,0,0,0,0,0,
  399.       1,1,1,1,1,1,1,1,
  400.       1,1,1,1,1,1,1,1,
  401.       0,0,0,0,0,0,0,0,
  402.       0,0,0,1,1,0,0,0,
  403.       0,0,0,1,1,0,0,0,
  404.  
  405.     };
  406.  
  407.   if((imagepnt & 63) == 0 || init)
  408.     {
  409.       imagestrt = RangeRand(4) * 64;
  410.       offsa = RangeRand(12) * 8;
  411.       astrt = offsa;
  412.       aend = offsa + 7;
  413.       offsb = RangeRand(12) * 8;
  414.       imagepnt = imagestrt;
  415.       if(RangeRand(25) == 0)
  416.         {
  417.           newcolor();
  418.           xcol = RangeRand(24) + 5;
  419.         }
  420.       offsa--;
  421.     }
  422.   if(++offsa > aend)
  423.     {
  424.       offsa = astrt;
  425.       offsb++;
  426.     }
  427.   color = (image[imagepnt++]) ? xcol : 0;
  428.   SetAPen(DrawRP,color);
  429. }
  430.  
  431. diag1(init)
  432. int init;
  433. {
  434.         offsb--;
  435.         if(offsa++ > 98) {
  436.                 offsa = 0;
  437.                 offsb++;
  438.                 nextcolor();
  439.         }
  440.         if(offsb < 0) {
  441.                 offsb = 99;
  442.         }
  443. }
  444.  
  445. diag2(init)
  446. int init;
  447. {
  448.         offsb++;
  449.         if(offsa++ > 98) {
  450.                 offsa = 0;
  451.                 offsb--;
  452.                 nextcolor();
  453.         }
  454.         if(offsb > 99) {
  455.                 offsb = 0;
  456.         }
  457. }
  458.  
  459. diag3(init)
  460. int init;
  461. {
  462.   static int cnt, cnt2;
  463.  
  464.   if(init) cnt = cnt2 = 0;
  465.  
  466.   offsb++;
  467.   if(offsa++ > 98)
  468.     {
  469.       offsa = 0;
  470.       offsb--;
  471.       color = 4;
  472.       SetAPen(DrawRP,color);
  473.       if(++cnt2 > 20) cnt2 = 0;
  474.     }
  475.   if(cnt++ > cnt2)
  476.     {
  477.       cnt = 0;
  478.       if(color++ > 30) color = 4;
  479.       SetAPen(DrawRP,color);
  480.     }
  481.   if(offsb > 99) offsb = 0;
  482. }
  483.  
  484. diag4(init)
  485. int init;
  486. {
  487.         offsb--;
  488.         if(offsa++ > 98) {
  489.                 offsa = 0;
  490.                 offsb++;
  491.         }
  492.         if(offsb < 0) {
  493.                 offsb = 99;
  494.         }
  495.   setcolor(((offsa * offsb) >> 4) & 31);
  496. }
  497.  
  498. sweep(init)
  499. int init;
  500. {
  501.   static int ainc, alen;
  502.  
  503.   if(init || alen > 51)
  504.     {
  505.       alen = ainc = offsa = offsb = 0;
  506.     }
  507.   if(ainc++ > alen)
  508.     {
  509.       offsb++;
  510.       ainc = 0;
  511.     }
  512.   if(offsa++ >= 99)
  513.     {
  514.       nextcolor();
  515.       alen++;
  516.       offsa = offsb = 0;
  517.     }  
  518. }
  519.  
  520. fadein(init)
  521. int init;
  522. {
  523.         offsa = RangeRand(99) + 1;
  524.         offsb = RangeRand(99) + 1;
  525.         setcolor(offsa / offsb);
  526. }
  527.  
  528. spiral(init)
  529. int init;
  530. {
  531.   static int sidecnt, sidelen, colorcnt, dirndx, adir, bdir;
  532.   static int newadir[] = {0,1,0,-1};
  533.   static int newbdir[] = {1,0,-1,0};
  534.  
  535.   if(init || offsa >= 99 || offsb >= 99)
  536.     {
  537.       sidecnt = 100;
  538.       sidelen = 0;
  539.       dirndx = 0;
  540.       offsa = RangeRand(99);
  541.       offsb = RangeRand(99);
  542.       colorcnt = 0;
  543.     }
  544.   if(sidecnt++ >= sidelen)
  545.     {
  546.       sidecnt = 0;
  547.       dirndx = (dirndx + 1) & 3;
  548.       if((dirndx & 1) == 0) sidelen++;
  549.       adir = newadir[dirndx];
  550.       bdir = newbdir[dirndx];
  551.     }
  552.   offsa += adir;
  553.   offsb += bdir;
  554.   if((colorcnt++ & 3) == 0) nextcolor();
  555.  
  556. }
  557.  
  558. spiral1(init)
  559. int init;
  560. {
  561.   static int sidecnt, sidelen, dirndx, adir, bdir, size;
  562.   static int newadir[] = {1,1,-1,-1};
  563.   static int newbdir[] = {1,-1,-1,1};
  564.  
  565.   if(init || offsa >= 99 || offsb >= 99 || sidelen >= size)
  566.     {
  567.       sidecnt = 100;
  568.       sidelen = 0;
  569.       dirndx = 0;
  570.       offsa = RangeRand(99);
  571.       offsb = RangeRand(99);
  572.       size = RangeRand(70);
  573.     }
  574.   if(sidecnt++ >= sidelen)
  575.     {
  576.       sidecnt = 0;
  577.       if(++dirndx > 3)
  578.         {
  579.           sidelen++;
  580.           offsa--;
  581.           dirndx = 0;
  582.           nextcolor();
  583.         }
  584.       adir = newadir[dirndx];
  585.       bdir = newbdir[dirndx];
  586.     }
  587.   offsa += adir;
  588.   offsb += bdir;
  589. }
  590.  
  591. zigstream(init)
  592. int init;
  593. {
  594.   static int sidecnt, sidelen, colorcnt, dirndx, adir, bdir;
  595.   static int newadir[] = {0,1};
  596.   static int newbdir[] = {1,0};
  597.  
  598.   if(init || offsa >= 99 || offsb >= 99)
  599.     {
  600.       sidecnt = 100;
  601.       sidelen = 0;
  602.       dirndx = 0;
  603.       offsa = RangeRand(99);
  604.       offsb = RangeRand(99);
  605.       colorcnt = 0;
  606.       setcolor(4);
  607.     }
  608.   if(sidecnt++ >= sidelen)
  609.     {
  610.       sidecnt = 0;
  611.       if((++dirndx & 1) == 0)
  612.         {
  613.           sidelen++;
  614.           dirndx = 0;
  615.         }
  616.       adir = newadir[dirndx];
  617.       bdir = newbdir[dirndx];
  618.     }
  619.   offsa += adir;
  620.   offsb += bdir;
  621.   if((colorcnt++ & 3) == 0) nextcolor();
  622.  
  623. }
  624.  
  625. formula1(init)
  626. int init;
  627. {
  628.   static int cona, conb, conx;
  629.  
  630.   if(init || offsa > 99)
  631.     {
  632.       offsa = 0;
  633.       offsb = -1;
  634.       cona = RangeRand(2) + 1;
  635.       conb = RangeRand(3) + 1;
  636.       conx = RangeRand(4) + 2;
  637.     }
  638.   if(offsb++ > offsa)
  639.     {
  640.       offsa++;
  641.       offsb = 0;
  642.     }
  643.   setcolor(((offsb * offsb * conb) - (offsa << cona)) >> conx);
  644. }
  645.  
  646. clr_screen()
  647. {
  648.   SetAPen(DrawRP,0);
  649.   RectFill(DrawRP,0,0,MAXX-1,MAXY-1);
  650.   SetAPen(DrawRP,color);
  651. }
  652.  
  653. cycolor()
  654. {
  655.   register int ndx, redtmp, greentmp, bluetmp;
  656.   register unsigned char reddir, greendir, bluedir;
  657.  
  658.   cyclecnt = 50;
  659.   redtmp = redvalue[1];
  660.   greentmp = greenvalue[1];
  661.   bluetmp = bluevalue[1];
  662.   
  663.   for(ndx = 1; ndx < 31; ndx++)
  664.     {
  665.       SetRGB4(DrawVP,
  666.               ndx,
  667.               (redvalue[ndx] = redvalue[ndx+1]),
  668.               (greenvalue[ndx] = greenvalue[ndx+1]),
  669.               (bluevalue[ndx] = bluevalue[ndx+1])
  670.              );
  671.     }
  672.   SetRGB4(DrawVP,
  673.           31,
  674.           (redvalue[31] = redtmp),
  675.           (greenvalue[31] = greentmp),
  676.           (bluevalue[31] = bluetmp)
  677.          );
  678.   if(RangeRand(100) != 0) return(0);
  679.   reddir = RangeRand(3) - 1;
  680.   greendir = RangeRand(3) - 1;
  681.   bluedir = RangeRand(3) - 1;
  682.   for(ndx = 1; ndx < 32; ndx++) /* smear some colors */
  683.     {
  684.       SetRGB4(DrawVP,
  685.           ndx,
  686.           (redtmp = redvalue[ndx] = (redtmp + reddir) & 15),
  687.           (greentmp = greenvalue[ndx] = (greentmp + greendir) & 15),
  688.           (bluetmp = bluevalue[ndx] = (bluetmp + bluedir) & 15)
  689.          );
  690.     }
  691.   if((reddir == 0) && (greendir == 0) && (bluedir == 0)) newcolor();
  692. }
  693.  
  694. do_dazzle(init)
  695. int init;
  696. {
  697.   static int (*currentfunc)();
  698.   static int type, typecnt, typetime;
  699.  
  700.   struct dotfuncs
  701.     {
  702.       int (*func)();
  703.       int maxtime;
  704.     };
  705.  
  706. /* add the names of the custom graphics functions here */
  707.   static struct dotfuncs dotfunc[] =
  708.     {
  709. /*    function name,    number of cycles to run (randomized) */
  710.  
  711.       formula1,        15000,
  712.       lotsadots,    6000,
  713.       streamer,        2000,
  714.       ribbons,        6000,
  715.       curves,        6000,
  716.       lines,        4000,
  717.       squares,        6000,
  718.       triangles,    8000,
  719.       zigzags,        6000,
  720.       grid,        6000,
  721.       diag1,        8000,
  722.       diag2,        8000,
  723.       diag3,        12000,
  724.       diag4,        12000,
  725.       sweep,        3000,
  726.       fadein,        15000,
  727.       spiral,        15000,
  728.       spiral1,        15000,
  729.       zigstream,    10000
  730.     };
  731.   int cnt;
  732.  
  733.   if(init)
  734.     {
  735.       typecnt = Backdrop->MouseY + Backdrop->MouseX;
  736.       for(cnt = 0; cnt++ < typecnt;) RangeRand(100); /* randomize */
  737.       newcolor();
  738.       cyclecnt = offsa = offsb = 0;
  739.       typecnt = 100;
  740.       typetime = 10;
  741.     }
  742.  
  743.   for(cnt = 0; cnt < 10; cnt++)
  744.     {
  745.       if(typecnt++ > typetime)
  746.         {
  747.           type = RangeRand((sizeof(dotfunc) / sizeof(struct dotfuncs)));
  748.           typecnt = 0;
  749.           typetime = RangeRand(dotfunc[type].maxtime);
  750.           if(RangeRand(5) == 0)
  751.             {
  752.               /* clear screen here */
  753.               clr_screen();
  754.               newcolor();
  755.             }
  756.           currentfunc = dotfunc[type].func;
  757.           (*currentfunc)(INIT); /* initialize */
  758.         }
  759.     (*currentfunc)(EXEC);                
  760.     if(offsa > 99) offsa = 99;
  761.     if(offsb > 99) offsb = 99;
  762.     if(cyclecnt-- <= 0) cycolor();
  763.  
  764.     WritePixel(DrawRP, col + offsb, row + offsa);
  765.     WritePixel(DrawRP, col + offsb, row - offsa);
  766.     WritePixel(DrawRP, col - offsb, row + offsa);
  767.     WritePixel(DrawRP, col - offsb, row - offsa);
  768.     WritePixel(DrawRP, col + offsa, row + offsb);
  769.     WritePixel(DrawRP, col + offsa, row - offsb);
  770.     WritePixel(DrawRP, col - offsa, row + offsb);
  771.     WritePixel(DrawRP, col - offsa, row - offsb);
  772.   }
  773. }
  774.  
  775. cleanitup()    /* release allocated resources */
  776. {
  777.    if (Backdrop)
  778.       CloseWindow(Backdrop);
  779.    if (Screen)
  780.       CloseScreen(Screen);
  781.    if (GfxBase)
  782.       CloseLibrary(GfxBase);
  783.    if (IntuitionBase)
  784.       CloseLibrary(IntuitionBase);
  785. }
  786.  
  787. setcolors()
  788. {
  789.    int ndx;
  790.  
  791.    SetRGB4(DrawVP, 0, 0, 0, 0);
  792.    for(ndx = 0; ndx < 32; ndx++) newcolor();
  793. }
  794.  
  795. initmenuitems()
  796. {
  797.    short n;
  798.  
  799.    for(n = 0; n < 3; n++) {  /* One struct for each item */
  800.       OnlyMenuItems[n].LeftEdge = 0;
  801.       OnlyMenuItems[n].TopEdge = 10 * n;
  802.       OnlyMenuItems[n].Width = 112;
  803.       OnlyMenuItems[n].Height = 10;
  804.       OnlyMenuItems[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  805.       OnlyMenuItems[n].MutualExclude = 0;
  806.       OnlyMenuItems[n].SelectFill = NULL;
  807.       OnlyMenuItems[n].Command = 0;
  808.       OnlyMenuItems[n].SubItem = NULL;
  809.       OnlyMenuItems[n].NextSelect = 0;
  810.  
  811.       OnlyMenuText[n].FrontPen = 0;
  812.       OnlyMenuText[n].BackPen = 1;
  813.       OnlyMenuText[n].DrawMode = JAM2;
  814.       OnlyMenuText[n].LeftEdge = 0;
  815.       OnlyMenuText[n].TopEdge = 1;
  816.       OnlyMenuText[n].ITextFont = NULL;
  817.       OnlyMenuText[n].NextText = NULL;
  818.    }
  819.    OnlyMenuItems[0].NextItem = &OnlyMenuItems[1]; /* next item */
  820.    OnlyMenuItems[1].NextItem = &OnlyMenuItems[2]; /* next item */
  821.    OnlyMenuItems[2].NextItem = NULL; /* Last item */
  822.  
  823.    OnlyMenuItems[0].ItemFill = (APTR)&OnlyMenuText[0];
  824.    OnlyMenuItems[1].ItemFill = (APTR)&OnlyMenuText[1];
  825.    OnlyMenuItems[2].ItemFill = (APTR)&OnlyMenuText[2];
  826.  
  827.  
  828.    OnlyMenuText[0].IText = (UBYTE *)"Show Title Bar";
  829.    OnlyMenuText[1].IText = (UBYTE *)"Pause";
  830.    OnlyMenuText[2].IText = (UBYTE *)"Exit";
  831. }
  832.  
  833. initmenu()
  834. {
  835.    OnlyMenu[0].NextMenu = NULL;                 /* No more menus */
  836.    OnlyMenu[0].LeftEdge = 0;
  837.    OnlyMenu[0].TopEdge = 0;
  838.    OnlyMenu[0].Width = 85;
  839.    OnlyMenu[0].Height = 10;
  840.    OnlyMenu[0].Flags = MENUENABLED;             /* All items selectable */
  841.    OnlyMenu[0].MenuName = "Options";
  842.    OnlyMenu[0].FirstItem = OnlyMenuItems;   /* Pointer to first item */
  843. }
  844.  
  845. main()
  846. {
  847.    ULONG class;
  848.    USHORT code, ItemNum;
  849.    int ndx, cnt;
  850.  
  851.    if (!(IntuitionBase =
  852.          (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  853.          exit(1);
  854.  
  855.    if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0))) {
  856.       cleanitup();
  857.       exit(2);
  858.    }
  859.  
  860.    if(!(Screen = (struct Screen *)OpenScreen(&MyScreen))) {
  861.       cleanitup();
  862.       exit(3);
  863.    }
  864.  
  865.    DrawWindow.Screen = Screen;
  866.  
  867.    if(!(Backdrop = (struct Window *)OpenWindow(&DrawWindow))) {
  868.       cleanitup();
  869.       exit(4);
  870.    }
  871.  
  872.  
  873.    DrawRP = Backdrop->RPort;     /* Draw into backdrop window */
  874.    DrawVP = &Screen->ViewPort;   /* Set colors in Screens VP  */
  875.  
  876.    setcolors();
  877.  
  878.    initmenuitems();
  879.    initmenu();
  880.    SetMenuStrip(Backdrop, &OnlyMenu[0]);
  881.    do_dazzle(INIT); /* initialize graphics variables */
  882.    ShowTitle(Screen, FALSE); /* start with title off */
  883.    TitleOn = PauseMode = FALSE;
  884.   
  885.    /* randomize based on starting mouse position */
  886.    cnt = (Backdrop->MouseY + Backdrop->MouseX) & 31;
  887.    for(ndx = 0; ndx++ < cnt;) RangeRand(100); /* randomize */
  888.    FOREVER {
  889.       while(message = (struct IntuiMessage *)GetMsg(Backdrop->UserPort)) {
  890.          class = message->Class;
  891.          code = message->Code;
  892.          ReplyMsg(message);
  893.  
  894.          if (class == MENUPICK && code != MENUNULL) {
  895.             ItemNum = ITEMNUM( code );
  896.             switch (ItemNum) {
  897.                case 0:
  898.                   /* turn title bar on and off */
  899.                   TitleOn = !TitleOn;
  900.                   if(TitleOn)
  901.                     OnlyMenuText[0].IText = (UBYTE *)"Hide Title Bar";
  902.                   else
  903.                     OnlyMenuText[0].IText = (UBYTE *)"Show Title Bar";
  904.                   ShowTitle(Screen, TitleOn);
  905.                   break;
  906.  
  907.                case 1:
  908.                   /* in and out of pause mode */
  909.                   PauseMode = !PauseMode;
  910.                   if(PauseMode)
  911.                     OnlyMenuText[1].IText = (UBYTE *)"Continue";
  912.                   else
  913.                     OnlyMenuText[1].IText = (UBYTE *)"Pause";
  914.                   break;
  915.  
  916.                case 2:
  917.                   /* good-by, so long */
  918.                   ClearMenuStrip(Backdrop);
  919.                   cleanitup();
  920.                   exit(0);
  921.             }
  922.          }
  923.       }
  924.       /* here is where we do the graphics */
  925.       if(!PauseMode) do_dazzle(EXEC);
  926.    }
  927. }
  928.